<template>
	<div class="paging">
		<nav>
			<el-pagination
			 background layout="prev, pager, next" 
			 :total="num" 
			 :page-size="pageData.pageSize"
			 :hide-on-single-page="true"
			 :current-page="pageData.curr"
			 @current-change="change"
			 @prev-click="pre"
			 @next-click="next">
			</el-pagination>
		</nav>
	</div>
</template>

<script>
	import bus from '../../../bus.js'
	
	export default {
		data() {
			return {
				pageData: {
					curr: 1, //当前页码
					pageSize: 10, //每页的数据个数
				}
			}
		},
		props: {
			num: Number
		},
		mounted() {
			this.sendData()
		},
		methods: {
			pre(val) {
				this.pageData.curr = val
				this.sendData()
			},
			next(val) {
				this.pageData.curr = val
				this.sendData()
			},
			change(val) {
				this.pageData.curr = val
				this.sendData()
			},
			//向topic兄弟组件传值
			sendData() {
				// this.$nextTick(function() {
					bus.$emit('pagedata', this.pageData)
				// })
			}
		},
	}
</script>

<style lang="scss" scoped>
	.paging {
		margin: 20px 0;
		nav {
			text-align: center;
		}
	}
</style>
